package com.example.zzl.adapter.SearchFragment;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.zzl.R;

import java.util.ArrayList;

/**
 * Created by zhang on 2017/2/11.
 */

public class SCAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<String> list;

    public SCAdapter(Context context, ArrayList<String> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override

    public long getItemId(int i) {
        return i;
    }

    @Override
    public int getViewTypeCount() {
        return 2;
    }

    @Override
    public int getItemViewType(int position) {
        if(list.get(position).equals("品牌") || list.get(position).equals("类别")){
            return 0;
        }else{
            return 1;
        }
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        switch(getItemViewType(i)) {
            case 0:
                ViewHolder vh;
            if (view == null) {
                view = View.inflate(context, R.layout.lv_actual_item_1, null);
                vh = new ViewHolder();
                vh.tv = (TextView) view.findViewById(R.id.tv_acu_1);
                view.setTag(vh);
            } else {
                vh = (ViewHolder) view.getTag();
            }
            vh.tv.setText(list.get(i));
                break;
            case 1:
                ViewHolder vh1;
                if (view == null) {
                    view = View.inflate(context, R.layout.lv_actual_item_2, null);
                    vh1 = new ViewHolder();
                    vh1.tv = (TextView) view.findViewById(R.id.tv_acu_2);
                    view.setTag(vh1);
                } else {
                    vh1 = (ViewHolder) view.getTag();
                }
                vh1.tv.setText(list.get(i));
                break;
        }
        return view;
    }

    class ViewHolder{
        TextView tv;
    }

}
